#!/bin/bash

SERVER_IP="$(curl members.3322.org/dyndns/getip 2>/dev/null)"
FLAG=">>> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # >>>"

day=3
if [ $# -eq 0 ] ; then
    echo "Usage:$0 {Order number} [number]"
    exit 1
fi
if [ -z $2 ] ; then
    day=3
else
    day=$2
fi
LOGDIR=("/ibu/flow/server-12021/logs" "/ibu/flow/server-12022/logs" "/ibu/flow/web-flow-7070/logs" "/ibu/flow/web-flow-7071/logs")

for log in ${LOGDIR[@]}
do
    cd $log
    #CMD=$(ls -t ibu-*.log|egrep -v "facade|sql")
    CMD=$(find ./ -name 'ibu-*.log' -mtime -$day | xargs ls -t | egrep -v "facade|sql")
    for file in $CMD
    do
        grep --color=auto -n -E "\b$1\b" $file
        if [ $? -eq 0 ] ; then 
            echo -e "\n
\033[33m$FLAG\033[0m
\033[33m>>>\033[0m IBU-1           
\033[33m>>>\033[0m ServerIP:\033[31m $SERVER_IP \033[0m
\033[33m>>>\033[0m DirName:\033[31m $(pwd) \033[0m
\033[33m>>>\033[0m FileName:\033[31m $file \033[0m
\033[33m$FLAG\033[0m\n"
       #break
       # else
       #     echo -e "\033[33m>>>\033[0m FileName:\033[31m $file is not found.\033[0m"
        fi
    done
done
